package hot100;

import java.util.LinkedList;
import java.util.List;

public class Solution155 {
    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.getMin());
    }

}

class MinStack {
    List<Integer> stack1;
    List<Integer> stack2;

    public MinStack() {
        stack1 = new LinkedList<>();
        stack2 = new LinkedList<>();
    }

    public void push(int val) {
        stack1.add(val);
        if (stack2.isEmpty() || val <= getMin()) stack2.add(val);
    }

    public void pop() {
        Integer i = stack1.remove(stack1.size() - 1);
        if (i == getMin()) stack2.remove(stack2.size() - 1);
    }

    public int top() {
        return stack1.get(stack1.size() - 1);
    }

    public int getMin() {
        return stack2.get(stack2.size() - 1);
    }
}